package com.roc.web.action.settlemgr;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;

public class SettlementMsgSearchCondition extends BaseSearchCondition{
	
	private static final long serialVersionUID = 1L;
	private String businessNum;//商户号
	private String minDate;
	private String maxDate;
	private String businessName;//商户简称
	private String insIdCd;//机构号
	private String freezeFlag;//状态
	private String type;//结算类型

	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {

		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();
		//商户号
		if(Constance.isNotEmpty(businessNum)){
			filedBeanList.add(new WhereHQLFieldBean("t.MCHT_CD",businessNum.trim(),"=",false));
		}
		
		if(Constance.isNotEmpty(insIdCd)){
			filedBeanList.add(new WhereHQLFieldBean("t.INS_ID_CD",insIdCd.trim(),"=",false));
		}
		if(Constance.isNotEmpty(freezeFlag)){
			filedBeanList.add(new WhereHQLFieldBean("t.FREEZEFLAG",freezeFlag.trim(),"=",false));
		}
		
		if(Constance.isNotEmpty(businessName)){
			filedBeanList.add(new WhereHQLFieldBean("t.MCHT_NAME", businessName.trim(),"LIKE", false, "ALL"));
		}
		
		if(Constance.isNotEmpty(minDate)){
//			filedBeanList.add(new WhereHQLFieldBean("t.SETTLEDATE", minDate.trim(), ">=", false));
			filedBeanList.add(new WhereHQLFieldBean("t.dt_create >= to_date('"+minDate.trim()+"', 'yyyymmdd')"));
		}
		if(Constance.isNotEmpty(maxDate)){
//			filedBeanList.add(new WhereHQLFieldBean("t.SETTLEDATE", maxDate.trim(), "<=", false));
			filedBeanList.add(new WhereHQLFieldBean("t.dt_create < to_date('"+maxDate.trim()+"', 'yyyymmdd' )+ 1 "));
		}
		if(Constance.isNotEmpty(type)){
			filedBeanList.add(new WhereHQLFieldBean("t.remark", type.trim(),"=", false));
		}
		
		return filedBeanList;
	}

	@Override
	protected String getRowCountHQL() {
		StringBuffer sb = new StringBuffer();
		sb.append("select count(1) from T_TRANSJNLS_SETTLE t,TBL_MCHT_INF tm,TBL_INS_INF ti");
		sb.append(" where t.MCHT_CD = tm.MCHT_CD and ti.INS_ID_CD = t.INS_ID_CD AND ti.INS_TYPE=1 ");
		return sb.toString();
	}

	@Override
	protected String getSearchHQL() {
		StringBuffer sb = new StringBuffer();
		sb.append("select t.ID,t.INS_ID_CD,t.MCHT_CD,t.MCHT_NAME,t.TRANS_AMT,t.TOTAL_NUM,t.MCHT_FEE,t.CHL_TRUE_FEE,");
				sb.append("t.MCHT_SET_AMT,t.BANK_NAME,t.BANK_CODE,t.ACCOUNT,t.ACCOUNT_NAME,t.ACC_TYPE,t.SETTLEDATE,");
				sb.append("t.SETTLEFLAG,t.SETDATE,t.FREEZEFLAG,to_char(t.DT_CREATE,'yyyyMMdd HH24miss'),to_char(t.DT_UPDATE,'yyyyMMdd HH24miss'),t.REMARK,t.REMARK1,t.REMARK2,t.REMARK3,t.REMARK4,ti.INS_COMPANY_CD ");
				sb.append("from T_TRANSJNLS_SETTLE t,TBL_MCHT_INF tm,TBL_INS_INF ti ");
				sb.append(" where t.MCHT_CD = tm.MCHT_CD and ti.INS_ID_CD = t.INS_ID_CD AND ti.INS_TYPE=1 ");
		return sb.toString();
	}

	@Override
	protected String getOrderPartOfHQL() {
		return "order by t.DT_CREATE desc";
	}

	public String getBusinessNum() {
		return businessNum;
	}

	public void setBusinessNum(String businessNum) {
		this.businessNum = businessNum;
	}

	public String getMinDate() {
		return minDate;
	}

	public void setMinDate(String minDate) {
		this.minDate = minDate;
	}

	public String getMaxDate() {
		return maxDate;
	}

	public void setMaxDate(String maxDate) {
		this.maxDate = maxDate;
	}

	public String getBusinessName() {
		return businessName;
	}

	public void setBusinessName(String businessName) {
		this.businessName = businessName;
	}

	public String getInsIdCd() {
		return insIdCd;
	}

	public void setInsIdCd(String insIdCd) {
		this.insIdCd = insIdCd;
	}

	public String getFreezeFlag() {
		return freezeFlag;
	}

	public void setFreezeFlag(String freezeFlag) {
		this.freezeFlag = freezeFlag;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
}
